package wsi.match;

import org.rygh.core.face.IHasName;
import org.rygh.core.xml.XmlPath;

public class XmlFunctionality implements IHasName {

	private final XmlPath xpath;
	private final double[] functionalities = new double[4];

	public XmlFunctionality(String value) {
		xpath = new XmlPath(value);
	}

	public boolean accept(XmlPath value) {
		return xpath.subsumesWithoutIndex(value);
	}

	public double get(int index) {
		return functionalities[index];
	}

	public double getCompleteFunctionality() {
		return functionalities[2];
	}

	public double getCompleteInverseFunctionality() {
		return functionalities[3];
	}

	@Override
	public String getName() {
		return xpath.stripIndex();
	}

	public XmlPath getXpath() {
		return xpath;
	}

	public void setFunctionalities(double[] values) {
		for (int i = 0; i < functionalities.length; i++)
			functionalities[i] = values[i];
	}

	@Override
	public String toString() {
		return String.format("%s: %.4f, %.4f, %.4f, %.4f", getName(),
				functionalities[0], functionalities[1], functionalities[2],
				functionalities[3]);
	}
}
